/**<P>Title:ucweb</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2010</p>
 *<p>Company: ucweb.com</p>
 *@author chensl@ucweb.com
 *@version 
 */
package com.ucweb.pooltest;

import com.ucweb.pooldemo.R;
import com.ucweb.pooltest.common.Constant;
import com.ucweb.pooltest.util.Setting;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
/**
 * @author chensl@ucweb.com
 * 
 *         下午4:56:56 2014-8-20
 */
public class SetInfoActivity extends ActionBarActivity {
	private EditText mSetInfoEditText;
	private int mode;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.fragment_set_info);
		getSupportActionBar().setDisplayShowHomeEnabled(true);
		Bundle bundle = getIntent().getExtras();
		mode = bundle.getInt(Constant.FLAG_MODE);
		initView();
	}

	private void initView() {
		mSetInfoEditText = (EditText) findViewById(R.id.set_info_id);
		Setting setting = Setting.getInstance();
		switch (mode) {
		case Constant.FLAG_SET_ALLOCATE_COUNT:
			mSetInfoEditText
					.setText(String.valueOf(setting.getAllocateCount()));
			break;
		default:
			throw new IllegalArgumentException("mode not defind!");
		}// end switch
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu_set_info, menu);
		return super.onCreateOptionsMenu(menu);
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			NavUtils.navigateUpFromSameTask(this);
			return true;
		case R.id.menu_item_save_id:
			String res = mSetInfoEditText.getText().toString().trim();
			if (!"".equals(res) && res != null) {
				switch (mode) {
				case Constant.FLAG_SET_ALLOCATE_COUNT:
					Setting.getInstance()
							.setAllocateCount(Integer.valueOf(res));
					break;
				default:
					throw new IllegalArgumentException("mode not defind!");
				}
			}// end if
			setResult(mode);
			finish();
			break;
		}
		return super.onOptionsItemSelected(item);
	}

}
